﻿package com.brilliance.common.interceptor;

/**
 * description:每一个Action都要被此拦截器拦截，此拦截器的目的是：打印出每次请求执行的路径
 * 1. 进入Action的method时记录log
 * 
 */

import com.brilliance.project.webapp.action.BaseAction;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class CommonInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		// 进入Action的method时记录log
		if (invocation.getAction() instanceof BaseAction) {
			BaseAction baseAction = (BaseAction) invocation.getAction();
			// 1. log出进入action的名称及方法
			baseAction.log.info(invocation.getAction().getClass().getName()
					+ "." + invocation.getProxy().getMethod() + "()");
			/**
			 * // 2. 跳过指定的action，不做登录及session timeout的检查 //
			 * 指定跳过的action设定在src/config/systemConfig.xml,key=uncheckActionName
			 * String path = this.getClass().getResource("/").getPath(); String
			 * uncheckActionName = PropertiesUtil.readValue(path +
			 * File.separator + "config" + File.separator +
			 * "systemConfig.properties", Constants.UNCHECKACTIONNAME); if
			 * (!uncheckActionName.contains(invocation.getAction().getClass()
			 * .getSimpleName())) { // 3. 假如没有登录，forwar到登录画面 if (null ==
			 * baseAction.getHttpServletRequest().getSession() || null ==
			 * baseAction.getAgent()) { return "login"; } }
			 */
		}
		String result = "";
		try {
			result = invocation.invoke();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
